# 指定文件夹占用大小查看（仅显示大于500M的文件夹）
PATH_TO_SCAN ?= /softwares/
FILE_PATTERN ?= "*"

.PHONY: help find-large-dirs find-files

# 默认目标，显示帮助信息
help:
	@echo "可用命令:"
	@echo "  make help              - 显示此帮助信息"
	@echo "  make find-large-dirs   - 查找并显示大于500M的文件夹 (PATH_TO_SCAN=$(PATH_TO_SCAN))"
	@echo "  make find-files        - 在指定路径下查找文件(不区分大小写) (PATH_TO_SCAN=$(PATH_TO_SCAN), FILE_PATTERN=$(FILE_PATTERN))"
	@echo ""
	@echo "参数:"
	@echo "  PATH_TO_SCAN          - 要扫描的路径，默认为 $(PATH_TO_SCAN)"
	@echo "                          示例: make find-large-dirs PATH_TO_SCAN=/home/user"
	@echo "  FILE_PATTERN          - 查找文件时的文件名模式，默认为 $(FILE_PATTERN)"
	@echo "                          示例: make find-files FILE_PATTERN=\"*.txt\""

find-large-dirs:
    @echo "Scanning large directories in $(PATH_TO_SCAN)"
    @du -h --threshold=500M --max-depth=1 "$(PATH_TO_SCAN)" | sort -hr

find-files:
	@echo "查找文件: 在 $(PATH_TO_SCAN) 路径下搜索 $(FILE_PATTERN) 模式的文件 (不区分大小写)"
	@find "$(PATH_TO_SCAN)" -type f -iname "$(FILE_PATTERN)" | sort